package inspection

//
//import (
//	"fmt"
//	"github.com/google/uuid"
//	cp "db2s/componentInit"
//	"db2s/global"
//	mq "db2s/topic-mq"
//	"reflect"
//	"runtime"
//	"strings"
//)
//
//func syncDataMQListenInitFunc(t, p int) map[cp.CheckMode][]*cp.MQTopicListeners {
//	MQListenersTable := map[Topic]*cp.MQTopicListeners{
//		//sync rows同步全量数据
//		syncIsSegmentQuery:       cp.NewMQTopicListeners(cp.Topic(syncIsSegmentQuery), t, 1, syncIsSegmentQueryListeners, 5, 10),
//		syncMissSegmentQuery:     cp.NewMQTopicListeners(cp.Topic(syncMissSegmentQuery), t, 1, syncMissSegmentQueryListeners, 5, 10),
//		syncIndexConcurrentQuery: cp.NewMQTopicListeners(cp.Topic(syncIndexConcurrentQuery), t*p, 1000, syncIndexConcurrentQueryListeners, 5, 20),
//		syncQueryTableSql:        cp.NewMQTopicListeners(cp.Topic(syncQueryTableSql), t*p, 1000, syncQueryTableSqlListeners, 1, 30),
//		syncQueryTableData:       cp.NewMQTopicListeners(cp.Topic(syncQueryTableData), t*p, 1000, syncQueryTableDataSqlListeners, 5, 41),
//		syncGenerlInsert:         cp.NewMQTopicListeners(cp.Topic(syncGenerlInsert), t*p*2, 1000, generalInsertListeners, 5, 42),
//		syncWriteInsert:          cp.NewMQTopicListeners(cp.Topic(syncWriteInsert), t*p*4, 1000, writeInsertListeners, 5, 43),
//	}
//	return map[cp.CheckMode][]*cp.MQTopicListeners{
//		"sync": {
//			MQListenersTable[syncIsSegmentQuery],
//			MQListenersTable[syncMissSegmentQuery],
//			MQListenersTable[syncIndexConcurrentQuery],
//			MQListenersTable[syncQueryTableSql],
//			MQListenersTable[syncQueryTableData],
//			MQListenersTable[syncGenerlInsert],
//			MQListenersTable[syncWriteInsert],
//		},
//	}
//}
//func topicCreateInit(checkmod string, t, p int) (m map[cp.CheckMode][]*cp.MQTopicListeners) {
//	//pc, _, _, _ := runtime.Caller(1)
//	//callingFunc := runtime.FuncForPC(pc)
//	//callFile, callLine := callingFunc.FileLine(pc)
//	//callFunc := callingFunc.Name()
//	//callFuncInfo := fmt.Sprintf("Call functions %v Call File %v:%v", callFunc, callFile, callLine)
//
//	m = make(map[cp.CheckMode][]*cp.MQTopicListeners)
//	if funcName, ok := MqListenerSInitFunc[checkmod]; ok {
//		if funcName.Kind() == reflect.Func {
//			m1 := funcName.Call([]reflect.Value{
//				reflect.ValueOf(t),
//				reflect.ValueOf(p),
//			})
//			for i := 0; i < len(m1); i++ {
//				m = m1[i].Interface().(map[cp.CheckMode][]*cp.MQTopicListeners)
//			}
//		}
//	}
//	return m
//}
//func GetCheckToTopicMQListeners() map[cp.CheckMode][]*cp.MQTopicListeners {
//	var (
//		t = GlobalPConfigs.rules.Mtc
//		r = GlobalPConfigs.rules.Mcc
//	)
//	//pc, _, _, _ := runtime.Caller(1)
//	//callingFunc := runtime.FuncForPC(pc)
//	//callFile, callLine := callingFunc.FileLine(pc)
//	//callFunc := callingFunc.Name()
//	//callFuncInfo := fmt.Sprintf("Call functions %v Call File %v:%v", callFunc, callFile, callLine)
//	return topicCreateInit(GlobalPConfigs.rules.CheckMode, t, r)
//}
//
//func (context *SchedulePlanContext) topicEndAdd(index CheckMode, topic Topic) {
//	context.AutoCloseMqComponentTable[cp.CheckMode(index)].TopicEndAdd(cp.Topic(topic))
//}
//func (context *SchedulePlanContext) topicEndMonit(index CheckMode, topic Topic) int64 {
//	return context.AutoCloseMqComponentTable[cp.CheckMode(index)].TopicEndMonit(cp.Topic(topic))
//}
//func (context *SchedulePlanContext) topicEndDelete(index CheckMode, topic Topic) {
//	context.AutoCloseMqComponentTable[cp.CheckMode(index)].TopicEndDelete(cp.Topic(topic))
//}
//
//func (context *SchedulePlanContext) topicEndDeleteNumber(index CheckMode, topic Topic, n int64) {
//	context.AutoCloseMqComponentTable[cp.CheckMode(index)].TopicEndDeleteNumber(cp.Topic(topic), n)
//}
//
//func sendMsg(check CheckMode, topic Topic, tableName string, msg map[string]any) bool {
//	var (
//		outfay string
//		event  = "[sendMsg]"
//		logseq int64
//		vlog   string
//	)
//	pc, _, _, _ := runtime.Caller(1)
//	callingFunc := runtime.FuncForPC(pc)
//	callFile, callLine := callingFunc.FileLine(pc)
//	callFunc := callingFunc.Name()
//	callFuncInfo := fmt.Sprintf("Call functions %v Call File %v:%v", callFunc, callFile, callLine)
//	vlog = fmt.Sprintf("(%d) %v %v Start sending topic messages, topic is {%v].", logseq, callFuncInfo, event, topic)
//	global.Wlog.Debug(vlog)
//	PlanContext.topicEndAdd(check, topic)
//	if v, ok := msg["logSeq"]; !ok {
//		vlog = fmt.Sprintf("(%d) %v %v The logseq value was not obtained and the sending failed.", logseq, callFuncInfo, event)
//		global.Wlog.Error(vlog)
//		return false
//	} else {
//		logseq = v.(int64)
//	}
//	if err := producer.Send(mq.Message{
//		Topic:      string(topic),
//		Body:       []byte(tableName),
//		Properties: msg,
//	}); err != nil {
//		global.Wlog.Error(fmt.Sprintf("(%d) %v %s Sending data check topic %v message failed", logseq, callFuncInfo, event, topic))
//		return false
//	}
//	if v, ok := msg["outFay"]; ok {
//		outfay = v.(string)
//	}
//	if strings.EqualFold(outfay, "bar") {
//		PlanContext.taskBarEndTopicAdd(msg)
//	}
//	vlog = fmt.Sprintf(fmt.Sprintf("(%d) %v %s Sending data check topic %v message successfully", logseq, callFuncInfo, event, topic))
//	global.Wlog.Debug(vlog)
//	return true
//}
//
//// 循环读取管道并发送消息
//func chanMonitorSendMsg(s chan any, checkMode CheckMode, topic Topic, tableName string, f sendTopicF, sm map[string]any, fatherSonTags map[string][]string, e sendEndDispos) bool {
//	var (
//		uid    uuid.UUID
//		vlog   string
//		event  = "[chanMonitorSendMsg]"
//		logseq int64
//	)
//	pc, _, _, _ := runtime.Caller(1)
//	callingFunc := runtime.FuncForPC(pc)
//	callFile, callLine := callingFunc.FileLine(pc)
//	callFunc := callingFunc.Name()
//	callFuncInfo := fmt.Sprintf("Call functions %v Call File %v:%v", callFunc, callFile, callLine)
//	vlog = fmt.Sprintf("(%d) %v %v Start reading chan and send topic messages.", logseq, callFuncInfo, event)
//	global.Wlog.Debug(vlog)
//	if v, ok := sm["logSeq"]; !ok {
//		vlog = fmt.Sprintf("(%d) %v %v The logseq value was not obtained and the sending failed.", logseq, callFuncInfo, event)
//		global.Wlog.Error(vlog)
//		return false
//	} else {
//		logseq = v.(int64)
//	}
//	for {
//		select {
//		case c, ok := <-s:
//			//time.Sleep(5 * time.Second)
//			if !ok {
//				e()
//				return true
//			} else {
//				var ms = make(map[string]any)
//				uid = uuid.New()
//				for k, v := range sm {
//					if strings.EqualFold(k, "sendMsgKey") {
//						ms[v.(string)] = c
//					} else {
//						ms[k] = v
//					}
//				}
//				//标签生成：
//				if v1, ok1 := ms["label"]; ok1 { //标签标识
//					for k2 := range v1.(map[string]any) { //循环集合
//						if strings.EqualFold(k2, "no") { //first label
//							ms["label"] = map[string]any{uid.String(): []string{}}
//							fatherSonTags[uid.String()] = []string{}
//						} else if len(k2) > 0 { //子级标签
//							if v4, ok4 := fatherSonTags[k2]; ok4 {
//								v4 = append(v4, uid.String())
//								fatherSonTags[k2] = v4
//							} else {
//								fatherSonTags[k2] = []string{uid.String()}
//							}
//							ms["label"] = map[string]any{k2: uid.String()}
//						}
//					}
//				}
//				if !f(checkMode, topic, tableName, ms) {
//					global.Wlog.Error(fmt.Sprintf("(%d) %v %s Sending data check topic %v message failed", logseq, callFuncInfo, event, topic))
//					return false
//				}
//			}
//		}
//	}
//}
//func deleteTopic(topicMsg map[string]any) {
//	var (
//		logseq int64
//		event  string
//		dtopic Topic
//		outfay = "bar"
//		vlog   string
//	)
//	pc, _, _, _ := runtime.Caller(1)
//	callingFunc := runtime.FuncForPC(pc)
//	callFile, callLine := callingFunc.FileLine(pc)
//	callFunc := callingFunc.Name()
//	callFuncInfo := fmt.Sprintf("Call functions %v Call File %v:%v", callFunc, callFile, callLine)
//	vlog = fmt.Sprintf("(%d) %v %v Start delete chan topic messages.", logseq, callFuncInfo, event)
//	global.Wlog.Debug(vlog)
//	if v, ok := topicMsg["logSeq"]; ok {
//		logseq = v.(int64)
//	}
//	if v, ok := topicMsg["event"]; ok {
//		event = v.(string)
//	}
//	if v, ok := topicMsg["dtopic"]; ok {
//		dtopic = v.(Topic)
//	}
//	if v, ok := topicMsg["outFay"]; ok {
//		outfay = v.(string)
//	}
//	PlanContext.topicEndDelete(getCheckMod(), dtopic)
//	if strings.EqualFold(outfay, "bar") {
//		PlanContext.TaskBarEndTopicDel(topicMsg)
//	}
//	global.Wlog.Debug(fmt.Sprintf("(%d) %v %s Delete data check topic %v successfully.", logseq, callFuncInfo, event, dtopic))
//}
